home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-24 | 4.3 KB | 189 lines | [TEXT/PJMM] |
- unit Prefix;
- interface
- uses
- DialogUtilities, ExternalInterface;
-
- procedure Main (callbacks: ExternalCallbackPtr; w: WindowPtr);
-
- implementation
-
- const
- selOnly = 3;
- insertButton = 4;
- deleteButton = 5;
- beginningOfLine = 6;
- endOfLine = 7;
- prefixString = 8;
-
- var
- prefixInfo: record
- insert: Boolean;
- lineStart: Boolean;
- selOnly: Boolean;
- pad: Boolean;
-
- prefixStr: Str255;
- end;
-
- procedure MaintainButtons (d: DialogPtr);
- begin
- SetDlgCtl(d, insertButton, prefixInfo.insert);
- SetDlgCtl(d, deleteButton, not prefixInfo.insert);
-
- SetDlgCtl(d, beginningOfLine, prefixInfo.lineStart);
- SetDlgCtl(d, endOfLine, not prefixInfo.lineStart);
-
- SetDlgCtl(d, selOnly, prefixInfo.selOnly);
- end;
-
- procedure Main (callbacks: ExternalCallbackPtr; w: WindowPtr);
- var
- d: DialogPtr;
- savePort: GrafPtr;
-
- actLen: Integer;
-
- selEnd, selStart, firstChar: LongInt;
- startLine, endLine: LongInt;
- oldStart: LongInt;
-
- item: Integer;
- text: Handle;
-
- s: Str255;
- scratch: Boolean;
-
- begin
- RememberA4;
- SetUpA4;
-
- PrepareCallbacks(callbacks);
-
- GetPort(savePort);
-
- d := CenterDialog(128);
- SetPort(d);
-
- GetSelection(selStart, selEnd, firstChar);
-
- GetPreference('Prfx', SizeOf(prefixInfo), @prefixInfo, actLen);
-
- if (actLen <= 0) then
- begin
- prefixInfo.insert := TRUE;
- prefixInfo.lineStart := TRUE;
- prefixInfo.prefixStr := '> ';
- prefixInfo.selOnly := (selEnd <> selStart);
- end;
-
- XAbleDlgCtl(d, selOnly, prefixInfo.selOnly);
- SetStrItem(d, prefixString, prefixInfo.prefixStr);
- SelIText(d, prefixString, 0, 255);
-
- repeat
- MaintainButtons(d);
- ModalDialog(@StandardFilter, item);
-
- case item of
- insertButton, deleteButton:
- prefixInfo.insert := (item = insertButton);
-
- beginningOfLine, endOfLine:
- prefixInfo.lineStart := (item = beginningOfLine);
-
- selOnly:
- prefixInfo.selOnly := not prefixInfo.selOnly;
- end;
- until (item = ok) or (item = cancel);
-
- ReadStrItem(d, prefixString, prefixInfo.prefixStr);
- DisposDialog(d);
-
- SetPort(savePort);
-
- if (item = ok) then
- begin
- SetPreference('Prfx', SizeOf(prefixInfo), @prefixInfo, actLen);
-
- startLine := 0;
- endLine := GetLastLine;
-
- if (prefixInfo.selOnly) then
- begin
- startLine := GetLineNumber(selStart);
- endLine := GetLineNumber(selEnd);
- end;
-
- if (Length(prefixInfo.prefixStr) <> 0) then
- begin
- s := prefixInfo.prefixStr;
-
- text := GetWindowContents(w);
- StartProgress('Changing Lines…', endLine - startLine, FALSE);
- oldStart := startLine;
-
- if (prefixInfo.lineStart) then
- begin
- if (prefixInfo.insert) then
- while (startLine < endLine) do
- begin
- scratch := DoProgress(startLine - oldStart);
- selStart := GetLinePos(startLine);
- SetSelection(selStart, selStart, firstChar);
- InsertText(@s[1], Length(s));
-
- startLine := startLine + 1;
- end
- else
- while (startLine < endLine) do
- begin
- scratch := DoProgress(startLine - oldStart);
- selStart := GetLinePos(startLine);
- if (FindPattern(text^, selStart + Length(s) + 1, selStart, @s[1], Length(s), FALSE) >= 0) then
- begin
- SetSelection(selStart, selStart + Length(s), firstChar);
- DeleteText;
- end;
-
- startLine := startLine + 1;
- end
- end
- else
- begin
- if (prefixInfo.insert) then
- while (startLine < endLine) do
- begin
- scratch := DoProgress(startLine - oldStart);
-
- selStart := GetLinePos(startLine);
- selStart := GetLineEnd(selStart);
- SetSelection(selStart, selStart, firstChar);
- InsertText(@s[1], Length(s));
-
- startLine := startLine + 1;
- end
- else
- while (startLine < endLine) do
- begin
- scratch := DoProgress(startLine - oldStart);
-
- selStart := GetLinePos(startLine);
- selEnd := GetLineEnd(selStart);
-
- if (FindPattern(text^, selEnd, selEnd - Length(s), @s[1], Length(s), FALSE) >= 0) then
- begin
- SetSelection(selEnd - Length(s), selEnd, firstChar);
- DeleteText;
- end;
-
- startLine := startLine + 1;
- end;
- end;
-
- DoneProgress;
- end;
- end;
-
- RestoreA4;
- end;
- end.